-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: bru.setNextRequest() #619
Conversation
@mj-h Some questions
|
Sure!
I truly appreciate your thoughts here. The |
Two thoughts on how
|
Chiming in with another real-world use case I would love to see supported before I can fully migrate my workloads from postman: A common pattern in our automation tests & cache-warming flows are to make a request to one endpoint which provides a list of available resources, and then issue a different request for each resource returned. So for example I will have a postman collection with 2 requests: I agree with @mj-h that Another approach which would enable my use-case, and presumably others, would be to inject a function you can call from scripting contexts to 'queue' additional requests. I suppose it would only make sense in the context of a collection run as opposed to executing a single request from the ui (then again, so does getNextRequest). But I'm thinking it could look something like this: // post-request script
// run is a new global variable, alongside `req`, `res`, `bru`, etc...
// requests is a list of requests defined in the running collection
// queue is a list of pending requests waiting to run
const { requests, queue } = run
// Find the request you want to queue. Solves 'globalness' problem
// in that you can only queue requests which you know exist. Does
// limit you to requests within the collection, though so no reaching
// out to other collections/folders (personally i think that's a good
// thing for maintainability/cohesion but could be convinced
// otherwise).
const newRequest = requests.find((r) => r.name === 'Get Foo')
// Create an instance of this request that will execute with specific
// variables that would supersede any pre-defined collection variables
// (solves the problem of having to modify collection state during run)
const toRun = newRequest.withVars({ ...overrideVars })
// Run new request last (after other queued requests)
queue.push(toRun)
// Run new request next (before other queued requests)
queue.unshift(toRun) What do you think? |
I talked to colleagues, and I checked usage on various GitHubs. My findings:
@bdentino: I did not encounter your scenario in our collections, but I did not check every collection in detail. In any case, I would say it's a rare (but still valid!) usage. Your proposal, however, boils down to a |
My proposal going forward:
|
Merged main and confirmed that it still works in UI and CLI. To be discussed: How to handle the "request name not found" case. Postman exited early here; with exit code 0, I believe. For easier compatibility, we could do the same. |
While testing this further, I noticed that there is no way to stop the collection runner once it started. But that's a separate issue (#143). |
@mj-h Thank you for leading the discussion around this. I'd like to spend some more time on this. Been busy with many other things. I will put some dedicated time towards this issue the coming week. PS: See v1.0.0 discussion |
Sure, happy to help! In the meantime, I'll add two missing behaviors:
Update: Behaviors added. They don't make the code prettier or the documentation easier -- but I still think they are worth it. |
This is especially useful for the bru cli, to make sure that test-runners that are accidentally stuck in an infinite loop still terminate in a reasonable amount of time and don't hog up resources.
For my usages, this feature is a mandatory prerequisite to move from Postman to Bruno, as it's a pillar to all my collections. |
const nextRequestName = result?.nextRequestName; | ||
if (nextRequestName !== undefined) { | ||
nJumps++; | ||
if (nJumps > 10000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be a parameter in bruno.json (the max number of jumps allowed) ? just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it -- but there are already a ton of config options... Do you have a use-case that needs it? If so, we can add it. If not, I would say YAGNI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAGNI it is then ;)
@helloanoop : Any news on if and/or when this can be included? I'm under pressure to migrate our API-tests away from newman, and I can stall my org for maybe one or two more weeks... |
@mj-h This will be included. I will spend some time on this and give you an update over this weekend. |
Thank you @mj-h for your work on this ! |
Its live 🎊 GUI - v1.4.0 |
@mlestoquoy I just released a patch fix for this in Can you install it and check if this issue is resolved ? |
Yes it works ! |
Description
This PR adds the method
bru.setNextRequest(requestName)
. It can be used in pre- and postrequest scripts (last write wins). It works in the collection-runner and in the CLI.Closes #534.
Contribution Checklist:
Usage::
Result in the UI Collection Runner
Result in the CLI